/*    */ package com.zimbra.cs.service.formatter;
/*    */ 
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.common.soap.Element.ElementFactory;
/*    */ import com.zimbra.common.soap.Element.XMLElement;
/*    */ import com.zimbra.cs.mailbox.CalendarItem;
/*    */ import com.zimbra.cs.mailbox.CalendarItem.Instance;
/*    */ import com.zimbra.cs.mailbox.MailItem;
/*    */ import com.zimbra.cs.mailbox.MailItem.Type;
/*    */ import com.zimbra.cs.service.UserServletContext;
/*    */ import com.zimbra.cs.service.mail.ToXML;
/*    */ import com.zimbra.cs.service.util.ItemIdFormatter;
/*    */ import java.io.IOException;
/*    */ import java.util.Collection;
/*    */ import java.util.Iterator;
/*    */ import java.util.Set;
/*    */ import javax.servlet.ServletOutputStream;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class XmlFormatter
/*    */   extends Formatter
/*    */ {
/*    */   public FormatterFactory.FormatType getType()
/*    */   {
/* 38 */     return FormatterFactory.FormatType.XML;
/*    */   }
/*    */   
/*    */   public Set<MailItem.Type> getDefaultSearchTypes()
/*    */   {
/* 43 */     return SEARCH_FOR_EVERYTHING;
/*    */   }
/*    */   
/*    */   public void formatCallback(UserServletContext context) throws ServiceException, IOException
/*    */   {
/* 48 */     Element elt = getFactory().createElement("items");
/* 49 */     ItemIdFormatter ifmt = new ItemIdFormatter(context.getAuthAccount(), context.targetMailbox, false);
/*    */     
/* 51 */     Iterator<? extends MailItem> iterator = null;
/*    */     try {
/* 53 */       long start = context.getStartTime();
/* 54 */       long end = context.getEndTime();
/* 55 */       boolean hasTimeRange = (start != -1L) && (end != -1L);
/* 56 */       iterator = getMailItems(context, start, end, 2147483647L);
/*    */       
/* 58 */       while (iterator.hasNext()) {
/* 59 */         MailItem item = (MailItem)iterator.next();
/* 60 */         if (((item instanceof CalendarItem)) && (hasTimeRange))
/*    */         {
/* 62 */           CalendarItem calItem = (CalendarItem)item;
/* 63 */           Collection<CalendarItem.Instance> instances = calItem.expandInstances(start, end, false);
/* 64 */           if (instances.isEmpty()) {}
/*    */         }
/*    */         else {
/* 67 */           ToXML.encodeItem(elt, ifmt, context.opContext, item, -4194305);
/*    */         }
/*    */       }
/* 70 */       context.resp.getOutputStream().write(elt.toUTF8());
/*    */     } finally {
/* 72 */       if ((iterator instanceof Formatter.QueryResultIterator))
/* 73 */         ((Formatter.QueryResultIterator)iterator).finished();
/*    */     }
/*    */   }
/*    */   
/*    */   Element.ElementFactory getFactory() {
/* 78 */     return Element.XMLElement.mFactory;
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/formatter/XmlFormatter.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */